package com.project.security;

import java.security.MessageDigest;

public class EncryptUtil {
	
	public static String encryptMD5(String str){
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			return bytesToHexString(md.digest(str.getBytes("UTF-8"))).toLowerCase();
		} catch (Exception e) {
			return "";
		}
	}
	
	public static final String bytesToHexString(byte[] bArray) {
		StringBuffer sb = new StringBuffer(bArray.length);
		String sTemp;
		for (int i = 0; i < bArray.length; i++) {
			sTemp = Integer.toHexString(0xFF & bArray[i]);
			if (sTemp.length() < 2)
				sb.append(0);
			sb.append(sTemp.toUpperCase());
		}
		return sb.toString();
	}
	
	public static void main(String arg[]){
		System.out.println(EncryptUtil.encryptMD5("123456"));
	}
}
